package com.pasabahceambalaj.session;

import javax.faces.model.SelectItem;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

import com.pasabahceambalaj.entity.Isemir;
import com.pasabahceambalaj.entity.Isemirbarkod;

@Name("isemirbarkodHome")
public class IsemirbarkodHome extends EntityHome<Isemirbarkod> {

	@In(create = true)
	IsemirHome isemirHome;

	public void setIsemirbarkodId(Long id) {
		setId(id);
	}

	public Long getIsemirbarkodId() {
		return (Long) getId();
	}

	@Override
	protected Isemirbarkod createInstance() {
		Isemirbarkod isemirbarkod = new Isemirbarkod();
		return isemirbarkod;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Isemir isemir = isemirHome.getDefinedInstance();
		if (isemir != null) {
			getInstance().setIsemir(isemir);
		}
	}

	public boolean isWired() {
		if (getInstance().getIsemir() == null)
			return false;
		return true;
	}

	public Isemirbarkod getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public SelectItem[] getBarkodTuru() {
		SelectItem[] items = new SelectItem[BARKODTURU.values().length];
		int i = 0;
		for (BARKODTURU g : BARKODTURU.values()) {
			items[i++] = new SelectItem(g.getCode(), g.getCode());
		}
		return items;
	}
	
	public enum BARKODTURU {
		EAN("EAN"), UPC("UPC");

		private final String code;

		private BARKODTURU(String code) {
			this.code = code;
		}

		public String getCode() {
			return this.code;
		}
	}
	
}
